@extends('admin.layout.index')
@section('content')
	<div class="span12">

		<!-- BEGIN EXAMPLE TABLE PORTLET-->

		<div class="portlet box light-grey">

			<div class="portlet-title">

				<div class="caption"><i class="icon-bookmark-empty"></i>角色列表</div>

				<div class="tools">


					<a href="javascript:;" class="reload"></a>


				</div>

			</div>

			<div class="portlet-body">

				<div class="clearfix">

					<div class="btn-group"style="float:left" >
						<a href="/admin/role/create" >
						<button id="sample_editable_1_new" class="btn green">

						添加新角色 <i class="icon-plus"></i>

						</button>
						</a>

					</div>
					<div class="row-fluid" style="float:right; width:500px;"><div class="span6" style="float:right; width:300px;"><div class="dataTables_filter" id="sample_1_filter">
						
					</div></div></div>


				</div>

				<table class="table table-striped table-bordered table-hover dataTable" id="sample_1" aria-describedby="sample_1_info">

					<thead>

						<tr role="row">
						
						<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 153.048px;">id</th>
						<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 153.048px;">角色名</th>
						<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 153.048px;">描述</th>
						<th class="sorting" role="columnheader" tabindex="0" aria-controls="sample_1" rowspan="1" colspan="1" aria-label="Username: activate to sort column ascending" style="width: 153.048px;">操作</th>

					</thead>

					@if (count($errors) > 0)
						<script>
							alert('{{ $errors }}');
						</script>
					@endif
				<tbody role="alert" aria-live="polite" aria-relevant="all">
					@foreach($data as $k=>$v)
					<tr class="gradeX odd">
						<td class=" ">{{$v['id']}}</td>
						<td class=" ">{{$v['name']}}</td>
						<td class=" ">{{$v['description']}}</td>
						<td class=" ">
							<a href="/admin/role/{{ $v['id'] }}"><button class="btn mini blue" style="float:left" ><i class="icon-file-text"></i> 授权</button></a>
							<span style="float:left" > &nbsp;| &nbsp;</span>
							<a href="/admin/role/{{ $v['id'] }}/edit"><button class="btn mini purple" style="float:left" onclick="delRole()"><i class="icon-edit"></i> 修改</button></a>
							<span style="float:left" > &nbsp;| &nbsp;</span>	 
								<button class="btn mini black" onclick="delRole({{ $v['id'] }})" ><i class="icon-trash"></i> 删除</button>
							
						</td>
					</tr>
					@endforeach

				</tbody></table><div class="row-fluid"><div class="span6"><div class="dataTables_info" id="sample_1_info"></div></div><div class="span6"><div class="dataTables_paginate paging_bootstrap pagination"></div></div></div></div>

			</div>

		</div>
		<script type="text/javascript">
			$('.pagination').addClass('dataTables_paginate paging_bootstrap')
			$('.disabled').addClass('prev')
		</script>
		<script>
		function delRole(roleid){

            layer.confirm('是否确认删除？', {
                btn: ['确认','取消'] //按钮
            }, function(){
                //            jQuery.post(url,data,success(data, textStatus, jqXHR),dataType)
                $.post('{{url('admin/role/')}}/'+roleid,{'_token':'{{csrf_token()}}','_method':'delete'},function(data){
                    //console.log(data);
//                    删除成功
                    if(data.status == 0){
                        layer.msg(data.msg, {icon: 6});
                        location.href = location.href;
                    }else{
                        layer.msg(data.msg, {icon: 5});
                        location.href = location.href;
                    }
                });

            }, function(){

            });




        }

//        $(function(){
//            //询问框

//        });

    </script>
		<!-- END EXAMPLE TABLE PORTLET-->

	</div>
@endsection